package com.hotel.controller;

import com.hotel.mapper.RoomMapper;
import com.hotel.pojo.Room;
import com.hotel.service.RoomService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

/**
 * @author shkstart  房间控制器
 * @create 2021-06-26 19:47
 */
@Controller
public class RoomController {

    @Autowired
    RoomService roomService;

    //跳转到房间管理界面
    @RequestMapping("/skip/toRoom")
    public String toRoomType(Model model) {
        List<Room> all = roomService.findAll();
        model.addAttribute("rooms",all);
        return "admin/views/room";
    }

    //跳转到房间添加界面
    @RequestMapping("/skip/toAddRoom")
    public String toAddRoom(){
        return "admin/views/add/RoomAdd";
    }

    //房间添加
    @RequestMapping("/AddRoom")
    public String AddRoom(Room room){
        boolean save = roomService.save(room);
        System.out.println("房间添加结果===>" + save);
        return "redirect:/skip/toRoom";
    }

    //跳转到房间修改界面
    @RequestMapping("/toUpdateRooms/{id}")
    public String toUpdateRoom(@PathVariable("id")Integer id,Model model){
        Room byId = roomService.getById(id);
        model.addAttribute("rooms" ,byId);
        return "admin/views/update/RoomUpdate";
    }

    //房间修改
    @RequestMapping("/updateRooms")
    public String UpdateRooms(Room room){
        boolean b = roomService.updateById(room);
        System.out.println("房间修改结果===>" + b);
        return "redirect:/skip/toRoom";
    }

    //删除房间
    @RequestMapping("/deletedRoom/{id}")
    public String deletedRoom(@PathVariable("id")Integer id){
        boolean b = roomService.removeById(id);
        System.out.println("房间删除结果为===>" + b);
        return "redirect:/skip/toRoom";
    }
}
